<!DOCTYPE html>
<html lang="zh_CN" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>更新角色信息</title>
    <header th:replace="header.html"></header>
    <link rel="stylesheet" th:href="@{/ztree/zTreeStyle/zTreeStyle.css}" />
    <link rel="stylesheet" th:href="@{/ztree/demo.css}" />
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" name="id" id="role_id" th:value="${sysRole.id}">
            <div class="layui-form-item">
                <label for="L_name" class="layui-form-label">
                    <span class="x-red">*</span>角色名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_name" th:value="${sysRole.name}" name="name" required="" lay-verify="name" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为角色名
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_description" class="layui-form-label">
                    <span class="x-red">*</span>描述
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_description" th:value="${sysRole.description}" name="description" required="" lay-verify="description" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    该角色的定位或权限范围
                </div>
            </div>
            <div class="layui-form-item">
                <label class="col-md-2 control-label layui-form-label">权限</label>
                <div class="col-md-10">
                    <ul id="treeDemo" class="ztree"></ul>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button  class="layui-btn layui-btn-danger" lay-filter="update" lay-submit="">
                    <i class="iconfont">&#xe6ad;</i>立即更新
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer', 'laydate', 'jquery'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;

        laydate.render({
            elem: '#L_birthday',
            format: 'yyyy-MM-dd',
            trigger: 'click'
        });

        //自定义验证规则
        form.verify({
            username: function (value) {
                if (value.length < 5) {
                    return '用户名至少得5个字符啊';
                }
            }
        });

        //监听提交
        form.on('submit(update)', function(data){
            var permissionIds = getCheckedMenuIds();
            data.field.permissionIds = permissionIds;
            $.ajax({
                url:"/role/edit",
                type:"POST",
                contentType: "application/json; charset=utf-8",
                data:JSON.stringify(data.field),
                dataType:'json',
                success:function(result){
                    layer.alert("更新成功", {icon: 6},function () {
                        //关闭当前frame
                        xadmin.close();
                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
                }
            });
            return false;
        });
    });
    $.fn.zTree.init($("#treeDemo"), getSettting(), getMenuTree());

    initMenuDatas($("#role_id").val());
</script>
</body>
</html>
